"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NewCommand = void 0;
const schematics_1 = require("../lib/schematics");
const abstract_command_1 = require("./abstract.command");
class NewCommand extends abstract_command_1.AbstractCommand {
    load(program) {
        program
            .command('new [name]')
            .alias('n')
            .description('Generate Cpaas application')
            .option('-d, --dry-run', 'Allow to test changes before executing the command')
            .option('-g, --skip-git', 'Allow to skip git repository initialization')
            .option('-s, --skip-install', 'Allow to skip packages installation')
            // .option('--pure', '创建一个不需要依赖于 cpaas 后端的前端脚手架')
            .option('--non-interactive', 'do not show interactive prompts')
            .option('-p, --package-manager [package-manager]', 'Allow to specify package manager to skip package-manager selection')
            // .option(
            //   '-l, --language [language]',
            //   'Language that shall be used (TS or JS)'
            // )
            // .option(
            //   '-c, --collection [collectionName]',
            //   'Collection that shall be used'
            // )
            .option('-set, --set [ENV_NAME=xxx]', '设置 cpaas 环境变量')
            .option('-demo, --demo-name [demoName]', '创建子模块名称')
            .option('--cpaas-packages [cpaasPackages]', 'Cpaas packages')
            .option('-hv, --cpaas-version [cpaasVersion]', 'Cpaas packages version')
            .option('-hcv, --cpaas-cli-version [cpaasCliVersion]', 'Cpaas cli version')
            .option('--registry [registry]', 'npm 地址默认值 http://nexus.coraise.cn/content/groups/cpaas-npm-group/')
            .option('-hfv, --cpaas-front-version [cpaasFrontVersion]', 'CpaasFront packages version')
            .action((name, command) => __awaiter(this, void 0, void 0, function* () {
            const options = [];
            options.push({ name: 'dry-run', value: !!command.dryRun });
            options.push({ name: 'skip-git', value: !!command.skipGit });
            options.push({ name: 'skip-install', value: !!command.skipInstall });
            options.push({
                name: 'package-manager',
                value: command.packageManager,
            });
            options.push({
                name: 'cpaasVersion',
                value: command.cpaasVersion || '',
            });
            options.push({
                name: 'cpaasCliVersion',
                value: command.cpaasCliVersion || '',
            });
            options.push({
                name: 'cpaasFrontVersion',
                value: command.cpaasFrontVersion || '',
            });
            options.push({
                name: 'cpaasPackages',
                value: !!command.cpaasPackages ? command.cpaasPackages : '',
            });
            options.push({
                name: 'nonInteractive',
                value: !!command.nonInteractive,
            });
            options.push({
                name: 'demoName',
                value: !!command.demoName ? command.demoName : '',
            });
            options.push({
                name: 'set',
                value: !!command.set ? command.set : '',
            });
            options.push({
                name: 'language',
                value: !!command.language ? command.language : 'ts',
            });
            options.push({
                name: 'collection',
                value: command.collection || schematics_1.Collection.CPAAS,
            });
            options.push({
                name: 'pure',
                value: !!command.pure,
            });
            options.push({
                name: 'registry',
                value: command.registry ||
                    'http://nexus.coraise.cn/content/groups/cpaas-npm-group/',
            });
            const inputs = [];
            inputs.push({ name: 'name', value: name });
            yield this.action.handle(inputs, options);
        }));
    }
}
exports.NewCommand = NewCommand;
